
@extends('master/master_index')

@section('title')
    <title>文章列表</title>
@endsection

@section('css')
    <link rel="stylesheet" type="text/css" href="{{asset('home/css/Topic_UserCenter.css')}}">
@endsection

@section('content')
        <div class="topic_list">
            <div class="msg_top">
                <ul>
                    <li class="click_bottom"><a href="{{url('section_list')}}/section={{$section_id}}">全部</a></li>
                    <li><a href="{{url('section_list')}}/section={{$section_id}}/best">精华</a></li>
                    <li><a href="{{url('section_list')}}/section={{$section_id}}/reply">评论</a></li>
                    <li><a href="{{url('section_list')}}/section={{$section_id}}/vote">点赞</a></li>
                    <li><a href="{{url('section_list')}}/section={{$section_id}}/time">时间</a></li>
                </ul>
            </div>
                <ul class="msg">

                </ul>
                <div class="d_a">
                    <a href="javascript:void(0)" onclick="page(1)">首页</a>
                    <a href="javascript:void(0)" onclick="page(<?php echo $prev ?>)">上一页</a>
                    @foreach($pp as $key=>$val)
                        @if($val == $page)
                            <span>{{$val}}</span>
                        @else
                            <a href="javascript:void(0)" onclick="page({{$val}})">{{$val}}</a>
                        @endif
                    @endforeach
                    <a href="javascript:void(0)" onclick="page(<?php echo $next ?>)">下一页</a>
                    <a href="javascript:void(0)" onclick="page(<?php echo $sums ?>)">尾页</a><br />
                </div>
        </div>
@endsection

@section('js')
<script type="application/javascript">
        var getUrl='{{url('section_list_change')}}';
        var id='{{$section_id}}';
        function page(page) {
            $.ajax({
                type: 'POST',
                url: getUrl,
                data: {pn: page,id:id},
                Type: 'json',
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
                },
                success: function (respond) {
                    if (respond){
                        $('.topic_list').html(respond);
                        $('body,html').animate({scrollTop:0},500);
                    }
                },
                error: function () {
                    alert('Ajax error!')
                }
            });
        }
        (function (window,$) {
            var message={
                isLoadAll:false,
                pn:1,
                init:function () {
                    this.addPage()
                    var self = this;
                    $(window).on('scroll',function () {
                        if (($(window).height()+$(window).scrollTop())>=$(document).height()){
                            if(!self.isLoadAll){
                                self.addPage();
                            }
                        }
                    });
                },
                addPage:function() {
                    var getUrl='{{url('section_list_add')}}';
                    var section_id='{{$section_id}}';
                    $.ajax({
                        type: 'POST',
                        url: getUrl,
                        data: {pn: this.pn,id:section_id},
                        Type: 'json',
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
                        },
                        success: function (respond) {
                            $('.msg').append(respond);
                        },
                        error: function () {
                            alert('Ajax error!')
                        }
                    });
                    this.pn++;
                    }
                };
            message.init();
        })(window,jQuery);
</script>
@endsection